Skip to content

Support push for Live Activity #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

morikuni
Copy link

@xiaotuotuo321
Copy link

hi bro

when the feature can be used?
i use the code in local. sending to firebase is successful, but the ios app no response.
show me the code.
can you help me to change?

Thanks!

package main

import (
	"context"
	firebase "firebase.google.com/go/v4"
	"firebase.google.com/go/v4/messaging"
	"fmt"
	"google.golang.org/api/option"
	"log"
	"os"
	"time"
)

func main() {
	println(os.Getwd())
	// 使用下载的服务账户密钥文件路径
	opt := option.WithCredentialsFile("./mePlus/to_firebase_ios/serviceAccountKey.json")
	app, err := firebase.NewApp(context.Background(), nil, opt)
	if err != nil {
		log.Fatalf("error initializing app: %v\n", err)
	}

	ctx := context.Background()
	client, err := app.Messaging(ctx)
	if err != nil {
		log.Fatalf("error getting Messaging client: %v\n", err)
	}
	now := time.Now()
	unixTime := time.Unix(1546304, 0)
	fcmOptions := new(messaging.APNSFCMOptions)
	fcmOptions.AnalyticsLabel = "test-live-activity"
	message := &messaging.Message{
		APNS: &messaging.APNSConfig{
			Headers: map[string]string{
				"apns-priority": "10",
				//"apns-topic":     "", // 必须添加的实时活动主题头
				"apns-push-type": "liveactivity", // 标识为实时活动推送
			},
			Payload: &messaging.APNSPayload{
				Aps: &messaging.Aps{
					Alert: &messaging.ApsAlert{
						Title: "123",
						Body:  "123",
					},
					//Sound:          "default",
					StaleDate:      &unixTime,
					Event:          messaging.LiveActivityEventStart,
					Attributes:     map[string]interface{}{},
					AttributesType: "MissedEnergy",
					ContentState:   map[string]interface{}{},
					DismissalDate:  &unixTime,
					Timestamp:      &now,
				},
			},
			FCMOptions:        fcmOptions,
			LiveActivityToken: "80a8a14077cc0e4392fbb5f4ae7bb329dbf0af5b8b384c5d1baba0a78b3227be3dbeba200dbfa150b8705f9364b0f5204d92267d82c093315911f9c9ed35be76a0c004c140c340d18644b2b7a513fd09",
		},
		Token: "dJ1H2SMWU0Q4lC6TI6_lED:APA91bGStzxLSXcpbPtwE_S8PcfOZt6Ob-BMAetQaenKa0WRtA6G731E1kAhzIjH4NvZsE1_37KYZmv-hBNWWg_F02Bwpc1rKopBhti1cOw_dGer8WHOLfg",
	}

	// 发送消息
	response, err := client.Send(ctx, message)
	if err != nil {
		log.Fatalf("error sending message: %v\n", err)
	}

	// 打印响应
	fmt.Printf("成功发送消息: %s\n", response)
}

@djain176
Copy link

djain176 commented May 2, 2025

HI Guys,
Please let us know when this pr will be merged, we also have dependency on this.
If possible then can we prioritised this pr

@lahirumaramba lahirumaramba self-requested a review May 12, 2025 20:23
@lahirumaramba lahirumaramba self-assigned this May 12, 2025
@osamingo
Copy link

@lahirumaramba Hi, I have a request regarding for code review of this 👀

The live_activity_token has to be defined in the same layer as the headers.
Therefore, using the current SDK, it's not possible to update LiveActivity remotely from the backend side. (the other hand, the payload can be resolved by using CustomData )

Please, code review if possible would be greatly appreciated 🙋🏼

@jonathanedey jonathanedey self-requested a review May 27, 2025 19:59
Copy link
Contributor

@jonathanedey jonathanedey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @morikuni, Thanks for getting started on this. Could you remove the extra fields added and limit to just LiveActivityToken field. Thanks!

Comment on lines +689 to +695
StaleDate *time.Time `json:"-"`
ContentState map[string]interface{} `json:"content-state,omitempty"`
Timestamp *time.Time `json:"-"`
Event LiveActivityEvent `json:"-"`
DismissalDate *time.Time `json:"-"`
AttributesType string `json:"attributes-type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the extra fields from this PR and focus on adding just the LiveActivityToken field. These live activity payload fields should be possible to add using the existing Aps.CustomData field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants